/*
 *  Buffer.h
 *  MusicAnalyzer
 *
 *  Created by jiro on 12/03/27.
 *  Copyright 2012 jiro music. All rights reserved.
 *
 */

#pragma once

#include <string>
#include <sstream>

namespace sc
{
	/**	@brief simple buffer class. 
		@remark this class has no responsiblity to delete data pointer. 
			user need to delete data pointer.
	*/
	class Buffer
	{
	public:

		Buffer()
			: byteCount( 0 ),
			  dataPtr( NULL )
		{}

		Buffer( int byteCount, uint8_t* ptr )
			: byteCount( byteCount ),
			  dataPtr( ptr )
		{}

		~Buffer()
		{}

		void Set( uint8_t* ptr, int byteCountArg )
		{
			dataPtr = ptr;
			byteCount = byteCountArg;
		}

		void WriteData( const uint8_t* ptr, int byteCountArg )
		{
			memcpy( dataPtr, ptr, byteCountArg );
			byteCount = byteCountArg;
		}
		
		void ZeroClear() { memset( dataPtr, 0x00, byteCount ); }

		std::string ToString( int tabCount = 0 ) const
		{
			std::string tabs;
			for ( int i = 0; i < tabCount; i++ )
			{
				tabs.append( "\t" );
			}

			std::stringstream ss;
			ss << tabs << "Buffer: dataPtr = 0x" << std::hex << (uint64_t) dataPtr << ", byte count = " << std::dec << byteCount
				<< ", data: ";
			for ( int i = 0 ; i < byteCount; i++ )
			{
				ss << std::hex << ( 0xff & dataPtr[ i ] ) << " ";
			}
			return ss.str();
		}

	public:

		uint8_t* dataPtr;	//	public for first accesse

		int byteCount;		//	public for first accesse
	
	private:
	};

}
